package net.base;

import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.ibatis.sqlmap.client.SqlMapClient;

/**
 * @author: jiangxiangwei
 * @date: 2009-12-15
 */
public class BaseDaoImpl implements BaseDao {
	public Logger log = Logger.getLogger(this.getClass());
	public SqlMapClient sqlMapClient;

	public SqlMapClient getSqlMapClient() {
		return sqlMapClient;
	}

	public void setSqlMapClient(SqlMapClient sqlMapClient) {
		this.sqlMapClient = sqlMapClient;
	}

	/**
	 * 数据库插入操作 单条插入
	 * 
	 * @param sqlid
	 * @param map
	 * @return
	 * @throws Exception
	 */
	public Object insert(String sqlid, Map map) throws Exception {
		return sqlMapClient.insert(sqlid, map);
	}

	/**
	 * 数据库删除操作 批量删除
	 * 
	 * @param sqlid
	 * @param ids
	 * @return
	 * @throws Exception
	 */
	public int delete(String sqlid, String id) throws Exception {
		return sqlMapClient.delete(sqlid, id);
	}

	/**
	 * 数据库更新操作 单条更新
	 * 
	 * @param sqlid
	 * @param map
	 * @return
	 * @throws Exception
	 */
	public int update(String sqlid, Map map) throws Exception {
		return sqlMapClient.update(sqlid, map);
	}

	/**
	 * 取列表 返回list
	 * 
	 * @param sqlid
	 * @param map
	 * @return
	 * @throws Exception
	 */
	public List getList(String sqlid, Map map) throws Exception {
		return sqlMapClient.queryForList(sqlid, map);
	}

	/**
	 * 取记录总数
	 * 
	 * @param sqlid
	 * @param map
	 * @return
	 * @throws Exception
	 */
	public int getListCount(String sqlid, Map map) throws Exception {
		Integer rtn = new Integer(0);
		rtn = (Integer) sqlMapClient.queryForObject(sqlid, map);
		return rtn;
	}

	/**
	 * 取单条数据 返回map
	 * 
	 * @param sqlid
	 * @param map
	 * @return
	 * @throws Exception
	 */
	public Map getMap(String sqlid, Map map) throws Exception {
		return (Map) sqlMapClient.queryForObject(sqlid, map);
	}
}
